<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>煤炭管理系统</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/lib/layui/css/layui-theme-custom.css">
    <link rel="stylesheet" href="/static/css/member.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <#include "/base/main-header.ftl">

    <#include "/base/main-left.ftl">
    <div class="layui-body">
        <!-- 内容主体区域  -->
        <div class="site-title">
            <fieldset>
                <legend>
                    <a class="site-title-text">采购申请查询</a>
                </legend>
            </fieldset>
        </div>
        <div class="table-box">
            <div class="site-text site-block">
                <form action="" class="layui-form">
                    <div class="layui-form-item">
                        <label for="memberName" class="myLable">采购单状态：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="" title="全部" checked="">
                            <input type="radio" name="status" value="0" title="草稿">
                            <input type="radio" name="status" value="1" title="审核中">
                            <input type="radio" name="status" value="2" title="已驳回">
                            <input type="radio" name="status" value="3" title="已发布">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="myLable">采购单号：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="billNumber"   autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <button id="query" class="layui-btn layui-btn-radius layui-inline">查询</button>
                    </div>
                </form>
            </div>
            <table class="layui-hide" id="prList" lay-filter="prTable"  ></table>
        </div>

    </div>
    <#include "/base/main-footer.ftl">
</div>

<script src="/static/lib/layui/layui.js"></script>
<script type="text/html" id="operator">
    {{#  if(d.status === '草稿' || d.status=== '已驳回'){ }}

    <button class="layui-btn layui-btn-xs" lay-event="edit">修改</button>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-xs" lay-event="detail">查看</button>
    {{#  } }}

</script>
<script>
    layui.use(['layer', 'form', 'element', 'jquery','table'], function () {
        let layer = layui.layer, form = layui.form, $ = layui.$, table = layui.table;

        var prList = table.render({
            elem: '#prList',
            url:'/PRList',
            method: 'post',
            contentType: 'application/json',
            cols: [[
                {field:'purchApplyId',width:250, title: '序号'}
                ,{field:'billNumber', width:180, title: '单据编号'}
                ,{field:'createDate', width:150, title: '创建日期'}
                ,{field:'coalType', width:80, title: '煤种'}
                ,{field:'purchaseNum',width:100, title: '数量（万吨）'}
                ,{field:'jiesuanMode', width:100, title: '结算方式'}
                ,{field:'createUserOrg', width:100, title: '发起人'}
                ,{field:'status', width:80, title: '状态'}
                ,{ title: '操作', toolbar: '#operator'}
            ]]
            ,page: true
            ,parseData: function(res){
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data.total,
                    "data": res.data.rows
                };
            }
        });
        $("#query").click(function (ele) {
            prList.reload({
                where:{
                    permitStatus: parseInt($("input[name='status']:checked").val()),
                    billNumber:$("input[name='billNumber']").val()
                }
            })
            return false
        })
        table.on('tool(prTable)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            if(layEvent === 'detail'){ //查看
                window.location = '/PRDetails?id='+data.purchApplyId
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除这条记录吗？', function(index){
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        type: "POST",
                        url: "/removePR.do?id="+data.purchApplyId,
                        success: function (data) {
                            if (data.isSuccess){
                                layer.msg("删除成功")
                            } else {
                                layer.msg(data.msg)
                            }
                        }
                    });
                });
            } else if(layEvent === 'edit'){ //编辑
               window.location = '/updatePR?id='+data.purchApplyId

            }
        });
    });
</script>
</body>
</html>